package com.community.mapper;

import com.community.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AdminMapper {
    @Insert("INSERT INTO user (username, password, is_admin) VALUES (#{username}, #{password}, #{isAdmin})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    int addUser(User user);

    @Delete("delete from user where user_id=#{userId}")
    int deleteUser(Integer userId);

    @Update("update user set password=#{newPassword} where user_id=#{userId}")
    int updatePassword(@Param("userId") Integer userId, @Param("newPassword")String newPassword);

    @Update("update user set username=#{username},password=#{password},is_admin=#{isAdmin} where user_id=#{userId}")
    int updateUser(User user);


    @Select("select user_id as userId,username,password,is_admin as isAdmin from user where user_id=#{userId}")
     User findUser(Integer userId);

    @Select("select user_id as userId,username,password,is_admin as isAdmin from user where username=#{username}")
   User findUserByUsername(String username);

    @Select("select user_id as userId,username,password,is_admin as isAdmin from user where is_admin=false")
    List<User> findAllUser();

}
